// 维护数据模块
import Vue from 'vue';
import * as recommend from '@/api/recommend';
import * as hotSong from '@/api/hot-song';
import * as search from '@/api/search';
import * as playList from '@/api/play-list';
import * as play from '@/api/play';

export default new Vue({
  data () {
    // 定义数据
    return {
      // 推荐歌单
      playList: [],
      // 新歌列表
      newSongList: [],
      // 热歌列表
      hotSongList: {},
      // 热搜列表
      searchHotList: [],
      // 搜索建议
      searchSuggest: [],
      // 最佳匹配
      searchMultimatch: {},
      // 搜索结果
      searchList: [],
      // 歌单详情
      playListDetail: {},
      // 歌单评论
      playListCommentList: {},
      // 歌词
      lyric: [],
    };
  },
  created () {
    // 改变数据
    // 更新推荐歌单
    this.$on('updatePlayList', async () => {
      this.playList = await recommend.getPlayList();
    });
    // 更新新歌列表
    this.$on('updateNewSongList', async () => {
      this.newSongList = await recommend.getNewSongList();
    });
    // 更新热歌列表
    this.$on('updateHotSongList', async () => {
      this.hotSongList = await hotSong.getHotSongList();
    });
    // 更新热搜列表
    this.$on('updateSearchHotList', async () => {
      this.searchHotList = await search.getSearchHot();
    });
    // 更新搜索建议
    this.$on('updateSearchSuggest', async (keyword) => {
      this.searchSuggest = await search.getSearchSuggest(keyword);
    });
    // 更新最佳匹配
    this.$on('updateSearchMultimatch', async (keyword) => {
      this.searchMultimatch = await search.getSearchMultimatch(keyword);
    });
    // 更新搜索结果
    this.$on('updateSearchList', async (keyword) => {
      this.searchList = await search.getSearchList(keyword);
    });
    // 更新歌单详情
    this.$on('updatePlayListDetail', async (id) => {
      this.playListDetail = await playList.getPlayListDetail(id);
    });
    // 更新歌单评论
    this.$on('updatePlayListCommentList', async (id) => {
      this.playListCommentList = await playList.getCommentList(id);
    });
    // 获取歌词
    this.$on('updateLyric', async (id) => {
      this.lyric = await play.getLyric(id);
    });
  },
});
